package com.bc.bcbuyerapihttp.controller;

import com.bc.bcapi.service.T_OrderService;
import com.bc.bcbuyerapihttp.common.UserContext;
import com.bc.bcmodel.BuyerUserInfo;
import com.bc.bcmodel.domain.T_User_buyer_infoModel;
import com.bc.bcmodel.req.DryOrderSubmitReq;
import com.bc.bcmodel.req.OrderSubmitInfoReq;
import com.bc.bcmodel.req.OrderSubmitReq;
import com.bc.bcmodel.resp.OrderProjectInfoResp;
import com.bc.commoncore.util.DateFormatUtilsExt;
import com.bc.commoncore.util.DateUtilsExt;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Name OrderController
 * @Description TODO
 * @Author douhaichao
 * @Date 2018/8/31 12:31
 * @Version 1.0
 **/
@Api("订单相关")
@RestController
@RequestMapping(value = "order")
public class OrderController {

    @Autowired
    T_OrderService t_orderService;

    @ApiOperation("获取提交订单信息")
    @RequestMapping(value = "getsubmitinfo", method = RequestMethod.POST)
    public JsonResult getSubmitInfo(@RequestBody OrderSubmitInfoReq req) {
        BuyerUserInfo userInfo =
                UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_orderService.getSubmitInfo(req);
    }

    @ApiOperation("提交订单")
    @RequestMapping(value = "submit", method = RequestMethod.POST)
    public JsonResult submit(@RequestBody
                                     OrderSubmitReq req) {
        BuyerUserInfo userInfo =
                UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setBuyer_user_id(userInfo.getUser_id());
        try {
            return t_orderService.submit(req);
        } catch (Exception e) {
            System.out.println(e.getMessage());
//            e.printStackTrace();
        }
        return new JsonResult(HttpReturnRnums.SystemError);
    }

    @ApiOperation("预提交订单")
    @RequestMapping(value = "drysubmit", method = RequestMethod.POST)
    public JsonResult drysubmit(@RequestBody DryOrderSubmitReq req) {
        BuyerUserInfo userInfo =
                UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        //req.setUser_id("1");
        return t_orderService.drysubmit(req);
    }

}
